package wicketcool.plugins;

import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * User: rabbit
 * Date: Jul 14, 2009
 */
@Component("info")
public class InfoPlugin implements Plugin {

    private Map<String, Plugin> plugins;

    public void run(List<String> arguments) {

        if (arguments.size() == 0 || arguments.get(0).equals("help")) {
            displayGeneralContent();
        }
        else if (arguments.get(0).equals("list") && arguments.get(1).equals("plugins")) {
            listAvailablePlugins();
        }
    }

    private void listAvailablePlugins() {
        System.out.println("Available plugins:");
        int index = 1;
        for (String key : plugins.keySet()) {
            System.out.println(index + ". " + key + " \t\t\t " + plugins.get(key).getDescription());
            index++;
        }
    }

    private void displayGeneralContent() {
        System.out.println("Running Wicket Cool Info Plugin.");
        System.out.println("Available actions:");
        System.out.println("wcl info help \t\t\t displays this content");
        System.out.println("wcl info list plugins \t\t\t displays all available plugins");
    }

    public void setPlugins(Map<String, Plugin> plugins) {
        this.plugins = new HashMap<String, Plugin>(plugins);
    }

    public String getDescription() {
        return "general information plugin";
    }
}
